package org.example.mine.controller;

import org.example.mine.service.BankCardService;
import org.example.model.common.Result;
import org.example.model.domain.express.ExpressDetial;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bankcard")
public class BankCardController {


    @Autowired
    BankCardService bankCardService;

    @GetMapping("/getbankcard/{registerIp}")
    public ExpressDetial getBankCard(@PathVariable("registerIp") String registerIp) {
        return bankCardService.getBankCard(registerIp);
    }
    @PostMapping("/addbankcard")
    public Result addbankcard(@RequestBody ExpressDetial expressDetial) {
        bankCardService.addbaxnkcard(expressDetial);
        return Result.build(200,"成功");
    }

    @Autowired
    RedisTemplate redisTemplate;

    @GetMapping("verification/{inputCode}/{phone}")
    public Result verification(@PathVariable("inputCode") String inputCode,@PathVariable("phone") String phone){
        Integer code = (Integer) redisTemplate.boundValueOps(phone).get();
        if(Integer.valueOf(inputCode).equals(code)){
            return Result.build(200,"验证成功");
        }
        return Result.build(500,"验证失败");
    }
}
